 /*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.groupb.circus.UserInterface;

import com.groupb.circus.impl_interfaces.*;
import com.groupb.circus.interfaces.Thumbnail;
import com.sun.media.jai.widget.DisplayJAI;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.image.renderable.ParameterBlock;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.media.jai.*;
import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import org.jivesoftware.smack.Roster;
import org.jivesoftware.smack.RosterEntry;
import org.jivesoftware.smack.packet.Message;



/**
 *
 * @author bhavna
 */
public final class UserInterfaceP extends JFrame {

    InstantMessage im = InstantMessage.getInstance();


    private static UserInterfaceP ui = null;
    private static String PathFotoaEditar;
    private PlanarImage ImatgeaEditar; // Variable on anirem guardant la foto modificada
    private int cphotos;// Comptador per anar guardant els fotos, i que es puguin guardar més d'una per sessiio
    private static Properties pr = null;
    
   private static String path = null;
   private static String download = null;
   private static String presentacio =null;
   private static String presentacioDos =null;
   private int size;
   private ChangeListener sizeAction;

int maxX=375; //Màxima apmlitud per al redimensionament
int maxY=375; //Màxima alçada per al redimensionament
float fX; //Amplada redimensionada
float fY; // Alçada redimensionada
   

    private UserInterfaceP(){
        
     try {   
        pr = new Properties();
        pr.load(UserInterfaceP.class.getClassLoader().getResourceAsStream("conquery.properties"));
        path = pr.getProperty("path/general");
        download = pr.getProperty("path/fotosDescarga");
        presentacio = pr.getProperty("path/presentacio");
        presentacioDos = pr.getProperty("path/presentacioDos");
                
      } catch (IOException ex) {
                Logger.getLogger(UserInterfaceP.class.getName()).log(Level.SEVERE, null, ex);
            }
      setSize(1000, 700);
      setResizable(true);
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      setLayout(new BorderLayout(0, 0));
      setVisible(true);
      initComponents();
}

    




    public static synchronized UserInterfaceP getInstance(){
        if (ui == null){
            
            ui = new UserInterfaceP();
            
            
        }
        
        return ui;
    }


    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTabbedPane1 = new javax.swing.JTabbedPane();
        SearchLayeredPane = new javax.swing.JLayeredPane();
        jScrollPane5 = new javax.swing.JScrollPane();
        jTextPane2 = new javax.swing.JTextPane();
        jRadioButtonKeyword = new javax.swing.JRadioButton();
        jRadioButtonUser = new javax.swing.JRadioButton();
        jButton3 = new javax.swing.JButton();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jScrollPane8 = new javax.swing.JScrollPane();
        jComboBox1 = new javax.swing.JComboBox();
        jRadioButtonTitle = new javax.swing.JRadioButton();
        jRadioButtonOntology = new javax.swing.JRadioButton();
        jRadioButtonLocalization = new javax.swing.JRadioButton();
        DownloadButton = new javax.swing.JButton();
        jScrollPane11 = new javax.swing.JScrollPane();
        jList1 = new javax.swing.JList();
        jButton20 = new javax.swing.JButton();
        ButtonShowNews = new javax.swing.JButton();
        MyPhotosLayeredPane = new javax.swing.JLayeredPane();
        jTextField2 = new javax.swing.JTextField();
        jRadioButton3 = new javax.swing.JRadioButton();
        jRadioButton4 = new javax.swing.JRadioButton();
        jRadioButton5 = new javax.swing.JRadioButton();
        jRadioButton6 = new javax.swing.JRadioButton();
        jRadioButton7 = new javax.swing.JRadioButton();
        jButton4 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jButton6 = new javax.swing.JButton();
        jButton7 = new javax.swing.JButton();
        jScrollPane9 = new javax.swing.JScrollPane();
        jButton18 = new javax.swing.JButton();
        EditorLayeredPane = new javax.swing.JLayeredPane();
        jButton8 = new javax.swing.JButton();
        jButton9 = new javax.swing.JButton();
        jButton10 = new javax.swing.JButton();
        jSeparator2 = new javax.swing.JSeparator();
        jButton11 = new javax.swing.JButton();
        jButton13 = new javax.swing.JButton();
        jButton14 = new javax.swing.JButton();
        jButton15 = new javax.swing.JButton();
        jButton16 = new javax.swing.JButton();
        jScrollPane10 = new javax.swing.JScrollPane();
        jSlider1 = new javax.swing.JSlider();
        jLabel9 = new javax.swing.JLabel();
        jButton12 = new javax.swing.JButton();
        jLabel10 = new javax.swing.JLabel();
        jSlider2 = new javax.swing.JSlider();
        jButton19 = new javax.swing.JButton();
        jLabel11 = new javax.swing.JLabel();
        jScrollPane6 = new javax.swing.JScrollPane();
        jTextPane3 = new javax.swing.JTextPane();
        ProfileLayeredPane = new javax.swing.JLayeredPane();
        jScrollPane3 = new javax.swing.JScrollPane();
        jTextPane1 = new javax.swing.JTextPane();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jTextField3 = new javax.swing.JTextField();
        jScrollPane4 = new javax.swing.JScrollPane();
        jTextArea2 = new javax.swing.JTextArea();
        jTextField4 = new javax.swing.JTextField();
        jTextField5 = new javax.swing.JTextField();
        jTextField6 = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jTabbedPane2 = new javax.swing.JTabbedPane();
        panel11 = new java.awt.Panel();
        ChatList = new java.awt.List();
        Delete = new javax.swing.JButton();
        Add = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        jScrollPane2 = new javax.swing.JScrollPane();
        jEditorPane1 = new javax.swing.JEditorPane();
        Send = new javax.swing.JButton();
        jButton17 = new javax.swing.JButton();

        jScrollPane5.setViewportView(jTextPane2);

        jScrollPane5.setBounds(90, 60, 130, 22);
        SearchLayeredPane.add(jScrollPane5, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jRadioButtonKeyword.setText("Keyword");
        jRadioButtonKeyword.setBounds(90, 110, 130, 23);
        SearchLayeredPane.add(jRadioButtonKeyword, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jRadioButtonUser.setText("User");
        jRadioButtonUser.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButtonUserActionPerformed(evt);
            }
        });
        jRadioButtonUser.setBounds(90, 130, 130, 23);
        SearchLayeredPane.add(jRadioButtonUser, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jButton3.setText("Search");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });
        jButton3.setBounds(90, 210, 97, 30);
        SearchLayeredPane.add(jButton3, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel7.setText("Results");
        jLabel7.setBounds(240, 40, 80, 14);
        SearchLayeredPane.add(jLabel7, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel8.setText("Downloads");
        jLabel8.setBounds(30, 350, 80, 14);
        SearchLayeredPane.add(jLabel8, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jScrollPane8.setBounds(230, 60, 370, 300);
        SearchLayeredPane.add(jScrollPane8, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Photos", "News" }));
        jComboBox1.setBounds(10, 60, 70, 20);
        SearchLayeredPane.add(jComboBox1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jRadioButtonTitle.setText("Title");
        jRadioButtonTitle.setBounds(90, 90, 130, 23);
        SearchLayeredPane.add(jRadioButtonTitle, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jRadioButtonOntology.setText("Ontology");
        jRadioButtonOntology.setEnabled(false);
        jRadioButtonOntology.setBounds(90, 150, 130, 23);
        SearchLayeredPane.add(jRadioButtonOntology, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jRadioButtonLocalization.setText("Localization");
        jRadioButtonLocalization.setBounds(90, 170, 130, 23);
        SearchLayeredPane.add(jRadioButtonLocalization, javax.swing.JLayeredPane.DEFAULT_LAYER);

        DownloadButton.setText("Download");
        DownloadButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                DownloadButtonActionPerformed(evt);
            }
        });
        DownloadButton.setBounds(119, 330, 100, 30);
        SearchLayeredPane.add(DownloadButton, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jScrollPane11.setViewportView(jList1);

        jScrollPane11.setBounds(20, 370, 430, 100);
        SearchLayeredPane.add(jScrollPane11, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jButton20.setText("View");
        jButton20.setEnabled(false);
        jButton20.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton20ActionPerformed(evt);
            }
        });
        jButton20.setBounds(470, 370, 130, 30);
        SearchLayeredPane.add(jButton20, javax.swing.JLayeredPane.DEFAULT_LAYER);

        ButtonShowNews.setText("View News");
        ButtonShowNews.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        ButtonShowNews.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ButtonShowNewsActionPerformed(evt);
            }
        });
        ButtonShowNews.setBounds(490, 30, 110, 23);
        SearchLayeredPane.add(ButtonShowNews, javax.swing.JLayeredPane.DEFAULT_LAYER);
        ButtonShowNews.setVisible(false);

        jTabbedPane1.addTab("Search", SearchLayeredPane);

        jTextField2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField2ActionPerformed(evt);
            }
        });
        jTextField2.setBounds(10, 50, 190, 20);
        MyPhotosLayeredPane.add(jTextField2, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jRadioButton3.setText("All");
        jRadioButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton3ActionPerformed(evt);
            }
        });
        jRadioButton3.setBounds(10, 80, 90, 23);
        MyPhotosLayeredPane.add(jRadioButton3, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jRadioButton4.setText("Animals");
        jRadioButton4.setBounds(10, 100, 90, 23);
        MyPhotosLayeredPane.add(jRadioButton4, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jRadioButton5.setText("Landscape");
        jRadioButton5.setBounds(10, 120, 90, 23);
        MyPhotosLayeredPane.add(jRadioButton5, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jRadioButton6.setText("Sports");
        jRadioButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton6ActionPerformed(evt);
            }
        });
        jRadioButton6.setBounds(10, 140, 90, 23);
        MyPhotosLayeredPane.add(jRadioButton6, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jRadioButton7.setText("Others");
        jRadioButton7.setBounds(10, 160, 90, 23);
        MyPhotosLayeredPane.add(jRadioButton7, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jButton4.setText("Search");
        jButton4.setEnabled(false);
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });
        jButton4.setBounds(110, 80, 90, 20);
        MyPhotosLayeredPane.add(jButton4, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jButton5.setText("Upload");
        jButton5.setEnabled(false);
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });
        jButton5.setBounds(20, 330, 120, 30);
        MyPhotosLayeredPane.add(jButton5, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jButton6.setText("Edit");
        jButton6.setEnabled(false);
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });
        jButton6.setBounds(20, 370, 120, 30);
        MyPhotosLayeredPane.add(jButton6, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jButton7.setText("Delete");
        jButton7.setEnabled(false);
        jButton7.setBounds(20, 410, 120, 30);
        MyPhotosLayeredPane.add(jButton7, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jScrollPane9.setBounds(210, 50, 400, 430);
        MyPhotosLayeredPane.add(jScrollPane9, javax.swing.JLayeredPane.DEFAULT_LAYER);
        File dir = new File(path);
        String[] ficheros = dir.list();
        String patho = pr.getProperty("path/general");

        JPanel matrix = new JPanel();
        JCheckBox [] arrayChk = new JCheckBox[ficheros.length];

        matrix.setLayout(new GridLayout(3,3));

        for(int y=0;y<ficheros.length;y++){

            ImageTh.setImage(patho+"/"+ficheros[y]);
            ImageTh.setImageBig(patho+"/"+ficheros[y]);
            arrayChk[y]= new JCheckBox();
            arrayChk[y].setIcon(ImageTh.getImage());
            arrayChk[y].setSelectedIcon(ImageTh.getImageBig());
            arrayChk[y].setDisabledIcon(ImageTh.getImage());

            matrix.add(arrayChk[y]);
        }

        jScrollPane9.setViewportView(matrix);

        jButton18.setText("Presentacio");
        jButton18.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton18ActionPerformed(evt);
            }
        });
        jButton18.setBounds(20, 450, 120, 30);
        MyPhotosLayeredPane.add(jButton18, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jTabbedPane1.addTab("My Photos", MyPhotosLayeredPane);

        jButton8.setText("Open");
        jButton8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton8ActionPerformed(evt);
            }
        });
        jButton8.setBounds(9, 30, 90, 20);
        EditorLayeredPane.add(jButton8, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jButton9.setText("<<");
        jButton9.setBounds(130, 30, 70, 20);
        EditorLayeredPane.add(jButton9, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jButton10.setText(">>");
        jButton10.setBounds(200, 30, 60, 20);
        EditorLayeredPane.add(jButton10, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jSeparator2.setBounds(0, 50, 600, 2);
        EditorLayeredPane.add(jSeparator2, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jButton11.setText("Grayscale");
        jButton11.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton11ActionPerformed(evt);
            }
        });
        jButton11.setBounds(430, 270, 170, 20);
        EditorLayeredPane.add(jButton11, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jButton13.setText("Apply");
        jButton13.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton13ActionPerformed(evt);
            }
        });
        jButton13.setBounds(520, 360, 70, 20);
        EditorLayeredPane.add(jButton13, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jButton14.setText("Blurring");
        jButton14.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton14ActionPerformed(evt);
            }
        });
        jButton14.setBounds(430, 70, 170, 20);
        EditorLayeredPane.add(jButton14, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jButton15.setText("Save");
        jButton15.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton15ActionPerformed(evt);
            }
        });
        jButton15.setBounds(430, 420, 90, 60);
        EditorLayeredPane.add(jButton15, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jButton16.setText("Return");
        jButton16.setBounds(515, 420, 90, 60);
        EditorLayeredPane.add(jButton16, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jScrollPane10.setBounds(20, 70, 390, 400);
        EditorLayeredPane.add(jScrollPane10, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jSlider1.setBounds(440, 130, 160, 40);
        EditorLayeredPane.add(jSlider1, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jSlider1.setPaintTicks(true);
        jSlider1.setMaximum(100);

        jSlider1.setSnapToTicks(true);

        jSlider1.addChangeListener(new ChangeBrightness());

        jLabel9.setText("                Brightness");
        jLabel9.setBounds(440, 100, 140, 30);
        EditorLayeredPane.add(jLabel9, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jButton12.setText("Original photo");
        jButton12.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton12ActionPerformed(evt);
            }
        });
        jButton12.setBounds(430, 390, 170, 23);
        EditorLayeredPane.add(jButton12, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel10.setText("Contrast");
        jLabel10.setBounds(490, 180, 70, 14);
        EditorLayeredPane.add(jLabel10, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jSlider2.setBounds(440, 210, 160, 30);
        EditorLayeredPane.add(jSlider2, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jSlider2.setPaintTicks(true);
        jSlider2.setMaximum(10);

        jSlider2.setSnapToTicks(true);

        jSlider2.addChangeListener(new ChangeContrast());

        jButton19.setText("Invert photo");
        jButton19.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton19ActionPerformed(evt);
            }
        });
        jButton19.setBounds(430, 300, 170, 23);
        EditorLayeredPane.add(jButton19, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel11.setText("          Image quality");
        jLabel11.setBounds(430, 330, 160, 20);
        EditorLayeredPane.add(jLabel11, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jScrollPane6.setViewportView(jTextPane3);

        jScrollPane6.setBounds(430, 360, 80, 22);
        EditorLayeredPane.add(jScrollPane6, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jTabbedPane1.addTab("Editor", EditorLayeredPane);

        jScrollPane3.setViewportView(jTextPane1);

        jScrollPane3.setBounds(30, 50, 140, 160);
        ProfileLayeredPane.add(jScrollPane3, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel1.setText("Name");
        jLabel1.setBounds(220, 50, 120, 14);
        ProfileLayeredPane.add(jLabel1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel2.setText("Email");
        jLabel2.setBounds(220, 80, 130, 14);
        ProfileLayeredPane.add(jLabel2, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel3.setText("Occupation");
        jLabel3.setBounds(220, 110, 150, 14);
        ProfileLayeredPane.add(jLabel3, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel4.setText("Country");
        jLabel4.setBounds(220, 140, 120, 14);
        ProfileLayeredPane.add(jLabel4, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel5.setText("Web link");
        jLabel5.setBounds(220, 170, 140, 14);
        ProfileLayeredPane.add(jLabel5, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel6.setText("Comments");
        jLabel6.setBounds(220, 200, 80, 14);
        ProfileLayeredPane.add(jLabel6, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jTextField1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField1ActionPerformed(evt);
            }
        });
        jTextField1.setBounds(310, 50, 160, 20);
        ProfileLayeredPane.add(jTextField1, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jTextField3.setBounds(310, 70, 160, 20);
        ProfileLayeredPane.add(jTextField3, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jTextArea2.setColumns(20);
        jTextArea2.setRows(5);
        jScrollPane4.setViewportView(jTextArea2);

        jScrollPane4.setBounds(300, 200, 270, 96);
        ProfileLayeredPane.add(jScrollPane4, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jTextField4.setBounds(310, 100, 160, 20);
        ProfileLayeredPane.add(jTextField4, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jTextField5.setBounds(310, 130, 160, 20);
        ProfileLayeredPane.add(jTextField5, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jTextField6.setBounds(310, 160, 160, 20);
        ProfileLayeredPane.add(jTextField6, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jButton1.setText("Edit");
        jButton1.setEnabled(false);
        jButton1.setBounds(390, 310, 80, 23);
        ProfileLayeredPane.add(jButton1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jButton2.setText("Save");
        jButton2.setEnabled(false);
        jButton2.setBounds(480, 310, 90, 23);
        ProfileLayeredPane.add(jButton2, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jTabbedPane1.addTab("Profile", ProfileLayeredPane);

        ChatList.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ChatListActionPerformed(evt);
            }
        });
        Roster roster = im.getRoster();

        for (Iterator<RosterEntry> i = roster.getEntries().iterator(); i.hasNext();) {
            RosterEntry re = (RosterEntry) i.next();
            ChatList.add(re.getUser());
        }

        Delete.setText("Delete");
        Delete.setEnabled(false);
        Delete.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                DeleteActionPerformed(evt);
            }
        });

        Add.setText("Add");
        Add.setEnabled(false);
        Add.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                AddActionPerformed(evt);
            }
        });

        jTextArea1.setColumns(20);
        jTextArea1.setRows(5);
        jTextArea1.setEditable(false);
        jScrollPane1.setViewportView(jTextArea1);

        jScrollPane2.setViewportView(jEditorPane1);

        Send.setText("Send");
        Send.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SendActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout panel11Layout = new org.jdesktop.layout.GroupLayout(panel11);
        panel11.setLayout(panel11Layout);
        panel11Layout.setHorizontalGroup(
            panel11Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(panel11Layout.createSequentialGroup()
                .addContainerGap()
                .add(panel11Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(panel11Layout.createSequentialGroup()
                        .add(panel11Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(panel11Layout.createSequentialGroup()
                                .add(8, 8, 8)
                                .add(Add, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 73, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(Delete, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 84, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                            .add(panel11Layout.createSequentialGroup()
                                .add(jScrollPane2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(Send)))
                        .add(0, 22, Short.MAX_VALUE))
                    .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)))
            .add(panel11Layout.createSequentialGroup()
                .add(ChatList, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 177, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(0, 26, Short.MAX_VALUE))
        );
        panel11Layout.setVerticalGroup(
            panel11Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(panel11Layout.createSequentialGroup()
                .add(ChatList, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 209, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(panel11Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(Add, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 21, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(Delete, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 21, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 146, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 10, Short.MAX_VALUE)
                .add(panel11Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                    .add(jScrollPane2)
                    .add(Send, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .add(15, 15, 15))
        );

        jTabbedPane2.addTab("Chat", panel11);

        jButton17.setText("Logout");
        jButton17.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton17ActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(19, 19, 19)
                .add(jTabbedPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 619, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jTabbedPane2)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                        .add(0, 0, Short.MAX_VALUE)
                        .add(jButton17)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jTabbedPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 514, Short.MAX_VALUE)
                    .add(layout.createSequentialGroup()
                        .add(0, 12, Short.MAX_VALUE)
                        .add(jButton17)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(jTabbedPane2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 468, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void DeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DeleteActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_DeleteActionPerformed

    private void AddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AddActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_AddActionPerformed

    private void ChatListActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ChatListActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_ChatListActionPerformed

    private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField1ActionPerformed

    private void jRadioButtonUserActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButtonUserActionPerformed
        // TODO add your handling code here:
        
    }//GEN-LAST:event_jRadioButtonUserActionPerformed

/*
 * Boton para enviar la palabra clave buscada (BOTON SEARCH)
 */
     
    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        // TODO add your handling code here:
        String word = jTextPane2.getText().toString();
        //search = new searchProfile(word);
        String[] users = ChatList.getItems();
        cont_rbutton =0;
        
        
       if(jComboBox1.getSelectedItem().equals("Photos") && jRadioButtonTitle.isSelected()){
           QueryType ="PHOTOTITLE";
           cont_rbutton++;
       }
       
       if(jComboBox1.getSelectedItem().equals("Photos") && jRadioButtonKeyword.isSelected()){
           QueryType ="PHOTOKEYWORD";
           cont_rbutton++;
       }
       
       if(jComboBox1.getSelectedItem().equals("Photos") && jRadioButtonUser.isSelected()){
           QueryType ="PHOTOUSER";
           cont_rbutton++;
       }
       
       if(jComboBox1.getSelectedItem().equals("Photos") && jRadioButtonOntology.isSelected()){
           QueryType ="PHOTOONTOLOGY";
           
       }
       
       if(jComboBox1.getSelectedItem().equals("Photos") && jRadioButtonLocalization.isSelected()){
           QueryType ="PHOTOLOCALIZATION";
           cont_rbutton++;
       }
       
       if(jComboBox1.getSelectedItem().equals("News") && jRadioButtonTitle.isSelected()) {
           QueryType = "NEWSTITLE";
           cont_rbutton++;
       }
       
       if(jComboBox1.getSelectedItem().equals("News") && jRadioButtonUser.isSelected()) {
           QueryType = "NEWSAUTHOR";
           cont_rbutton++;

       }
              
       if(jComboBox1.getSelectedItem().equals("News") && jRadioButtonKeyword.isSelected()) {
           QueryType = "NEWSPARAGRAPH";
           cont_rbutton++;
       }
       
       search = new searchProfile(word,QueryType);


       if(cont_rbutton == 1){
           for(int i=0;i<users.length;i++){
            
            im.SendSearchProfile(users[i], search);
            
        }
       }else{
        JFrame error = new JFrame();
        JLabel label = new JLabel("You have to Select one radioButton",SwingConstants.CENTER);
        
        error.setVisible(true);
        error.setSize(300, 150);
        error.setLocation(50, 50);
        
        error.getContentPane().add(label, BorderLayout.CENTER);
           
       }
       
       
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jRadioButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton3ActionPerformed
        // TODO add your handling code here:
        
    }//GEN-LAST:event_jRadioButton3ActionPerformed

    private void jRadioButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton6ActionPerformed
        // TODO add your handling code here:
        
    }//GEN-LAST:event_jRadioButton6ActionPerformed

    private void jTextField2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField2ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField2ActionPerformed

    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
        // TODO add your handling code here:
       
    }//GEN-LAST:event_jButton6ActionPerformed

    /*
     * Boto que ocnverteix foto a escala de grisos
     */

    private void jButton11ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton11ActionPerformed

 PlanarImage image = JAI.create("fileload", PathFotoaEditar); // Crear PLanarimage de la imatge seleccionada per mitja del path
      

 image=GrayscaleImage(image); // Convolucionem la imatge

// Ajustem als maxims tamanys de l'aplicació

float a= image.getWidth();
float b= image.getHeight();
float s1=(float)fX/a;
float s2=(float)fY/b;

image=scaleImage(image,s1,s2);
ImatgeaEditar=image;
// Mostrar la planaImatge en el jScrollPane10
DisplayJAI display = new DisplayJAI(image);
JPanel jPanel2 = new JPanel();
jPanel2.add(display,BorderLayout.CENTER);
jPanel2.setVisible(true);
jScrollPane10.getViewport().add(jPanel2);
       
    }//GEN-LAST:event_jButton11ActionPerformed

   
   /*
    * Blurring
    */

    private void jButton14ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton14ActionPerformed


PlanarImage image = JAI.create("fileload", PathFotoaEditar); // Crear PLanarimage de la imatge seleccionada per mitja del path
image=convolveImage(image); // Convolucionem la imatge

// Ajustem als maxims tamanys de l'aplicació

float a= image.getWidth();
float b= image.getHeight();
float s1=(float)fX/a;
float s2=(float)fY/b;

image=scaleImage(image,s1,s2);
ImatgeaEditar=image;
// Mostrar la planaImatge en el jScrollPane10
DisplayJAI display = new DisplayJAI(image);
JPanel jPanel2 = new JPanel();
jPanel2.add(display,BorderLayout.CENTER);
jPanel2.setVisible(true);
jScrollPane10.getViewport().add(jPanel2);
  
 
    }//GEN-LAST:event_jButton14ActionPerformed

    /*
     * Boton guardar
     */

    private void jButton15ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton15ActionPerformed

//Metode que salva la imatge i la guarda en el directori de descarregues.
       // PlanarImage image = JAI.create("fileload", PathFotoaEditar);
        String format= "JPEG";
        String archivo=download+"/Imatge editada"+cphotos+"."+format;
        FileOutputStream salida;
 
        try {
            salida = new FileOutputStream(archivo);

                guardarImage(ImatgeaEditar,salida,archivo,format);
                cphotos++;
        } catch (FileNotFoundException ex) {
            Logger.getLogger(UserInterfaceP.class.getName()).log(Level.SEVERE, null, ex);
        }
       
      
    }//GEN-LAST:event_jButton15ActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed


    }//GEN-LAST:event_jButton4ActionPerformed

    
    
    private void SendActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SendActionPerformed
       
        
        
        
        im.sendChat(ChatList.getSelectedItem().toString(),jEditorPane1.getText().toString() );
        jTextArea1.append("Yo: "+jEditorPane1.getText()+ "\n");
        jEditorPane1.setText("");

        
        
    }//GEN-LAST:event_SendActionPerformed

    
    /*
     * Boton para cerrar la aplicacion
     */
    private void jButton17ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton17ActionPerformed
        
        im.logout();
        System.exit(0);
        this.setVisible(false);
        
    }//GEN-LAST:event_jButton17ActionPerformed
/*
 * Boton open del editor
 */
    private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton8ActionPerformed
       
       final JFileChooser fc = new JFileChooser();
       int returnVal = fc.showOpenDialog(UserInterfaceP.this);
       JLabel ima;

        
       if (returnVal == JFileChooser.APPROVE_OPTION) {
        			File ofile = fc.getSelectedFile();
                               // String pathOne = ofile.getPath();
                               PathFotoaEditar =ofile.getPath();
                               // ima = new JLabel(loadImage(pathOne));
                                ima = new JLabel(loadImage(PathFotoaEditar));
                                ImatgeaEditar=JAI.create("fileload", PathFotoaEditar);
                                jScrollPane10.getViewport().add(ima);
                           
                     		}
        
        
    }//GEN-LAST:event_jButton8ActionPerformed


/*
 * Mètode canviar la lluminositat
 */
    
public class ChangeBrightness implements ChangeListener{
 
     public void stateChanged(ChangeEvent ce){

         int value = jSlider1.getValue();
PlanarImage image = JAI.create("fileload", PathFotoaEditar);

    value=value-50;
  image=brightnessImage(image,value);

float a= image.getWidth();
float b= image.getHeight();
float s1=(float)fX/a;
float s2=(float)fY/b;

image=scaleImage(image,s1,s2);
ImatgeaEditar=image;
// Mostrar la planaImatge en el jScrollPane10
DisplayJAI display = new DisplayJAI(image);
JPanel jPanel2 = new JPanel();
jPanel2.add(display,BorderLayout.CENTER);
jPanel2.setVisible(true);
jScrollPane10.getViewport().add(jPanel2);

  
  }
}

/*
 * Metode per canviar el contrast
 */
public class ChangeContrast implements ChangeListener{

     public void stateChanged(ChangeEvent ce){

     int value = jSlider2.getValue();
     PlanarImage image = JAI.create("fileload", PathFotoaEditar);
     float contrast;
    contrast=(float)value/10;

    image=contrastImage(image,contrast);
    
float a= image.getWidth();
float b= image.getHeight();
float s1=(float)fX/a;
float s2=(float)fY/b;

image=scaleImage(image,s1,s2);
ImatgeaEditar=image;

// Mostrar la planaImatge en el jScrollPane10
DisplayJAI display = new DisplayJAI(image);
JPanel jPanel2 = new JPanel();
jPanel2.add(display,BorderLayout.CENTER);
jPanel2.setVisible(true);
jScrollPane10.getViewport().add(jPanel2);

  }
}


    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
         
    }//GEN-LAST:event_jButton5ActionPerformed

    /*
     * Boton visualizacion presneacion
     */
    private void jButton18ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton18ActionPerformed



      String directoriPhotos=presentacio;
      String directoriHTML5=presentacioDos;
        Presentacio P = new Presentacio();
        P.getPresentacio(directoriPhotos, directoriHTML5, "Presentation");
    }//GEN-LAST:event_jButton18ActionPerformed

    /*
     * Boto que et retorna a la foto original
     */

    private void jButton12ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton12ActionPerformed

PlanarImage image = JAI.create("fileload", PathFotoaEditar); // Crear PLanarimage de la imatge seleccionada per mitja del path


// Ajustem als maxims tamanys de l'aplicació

float a= image.getWidth();
float b= image.getHeight();
float s1=(float)fX/a;
float s2=(float)fY/b;

image=scaleImage(image,s1,s2);
ImatgeaEditar=image;
// Mostrar la planaImatge en el jScrollPane10
DisplayJAI display = new DisplayJAI(image);
JPanel jPanel2 = new JPanel();
jPanel2.add(display,BorderLayout.CENTER);
jPanel2.setVisible(true);
jScrollPane10.getViewport().add(jPanel2);

    }//GEN-LAST:event_jButton12ActionPerformed

    private void DownloadButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DownloadButtonActionPerformed
      
        download = pr.getProperty("path/fotosDescarga");
        if(result.Content().size()!=0){ // modificar
           
            ArrayUc = new ArrayList(Chk.length);
       
            /*
             * Recorro el array de checkbox para saber cual esta seleccionado y generar una lista de UserContent
            */
            for(int i=0;i<Chk.length;i++){
                
                if(Chk[i].isSelected()){
                    Uc = new UserContent(contents[i].getUser(),contents[i].getPath());
                    ArrayUc.add(Uc);
                }
            }
            
           
            
            
           for (iterador = ArrayUc.listIterator(); iterador.hasNext(); ) {
                  UserContent UserC = (UserContent) iterador.next();
                  im.SendUserContent(UserC,download);
                
           } 

           
            
        }
        
        
        
        
    }//GEN-LAST:event_DownloadButtonActionPerformed

    /*
     * Boto per invertir la imatge
     */

    private void jButton19ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton19ActionPerformed
       PlanarImage image = JAI.create("fileload", PathFotoaEditar); // Crear PLanarimage de la imatge seleccionada per mitja del path
image=invertImage(image); // Invertim la imatge

// Ajustem als maxims tamanys de l'aplicació

float a= image.getWidth();
float b= image.getHeight();
float s1=(float)fX/a;
float s2=(float)fY/b;

image=scaleImage(image,s1,s2);
ImatgeaEditar=image;

// Mostrar la planaImatge en el jScrollPane10
DisplayJAI display = new DisplayJAI(image);
JPanel jPanel2 = new JPanel();
jPanel2.add(display,BorderLayout.CENTER);
jPanel2.setVisible(true);
jScrollPane10.getViewport().add(jPanel2);
    }//GEN-LAST:event_jButton19ActionPerformed

    /*
     * Boto per qualitat
     */

    private void jButton13ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton13ActionPerformed

        // Et guarda la imatge, amb la qualitat que l'usuari afegeix al panell de text, al PATH de descarrgues.
        //El canvi de qualitat NO es mostra a l'editor, a diferencia de totes les altres opcions (contrast...)

 String num;
num =jTextPane3.getText();
float quality = Float.parseFloat(num);

if(quality>1){

    quality=1;
}

if(quality<0){

    quality=0;
}

        System.out.println(num);

        FileOutputStream salida;
        try {
             
       
        String archivo=download+"/Imatge qualitat"+cphotos+".jpg";
            salida = new FileOutputStream(archivo);
            Imatge.encodeImage(ImatgeaEditar, salida, quality, archivo);
            cphotos++;

        } catch (FileNotFoundException ex) {
            Logger.getLogger(UserInterfaceP.class.getName()).log(Level.SEVERE, null, ex);
        }


    }//GEN-LAST:event_jButton13ActionPerformed







    private void jButton20ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton20ActionPerformed
        JFrame nuevo = new JFrame();
        ImageIcon photoShow= new ImageIcon(download+"/"+jList1.getSelectedValue().toString());
        JLabel label = new JLabel("",SwingConstants.CENTER);
        label.setIcon(photoShow);
        
        nuevo.setVisible(true);
        nuevo.setSize(600, 600);
        nuevo.getContentPane().add(label, BorderLayout.CENTER);

    }//GEN-LAST:event_jButton20ActionPerformed

    /*
     * Boton mostrar noticias
     */
    private void ButtonShowNewsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ButtonShowNewsActionPerformed
   /*
    * MOSTRAR EL CONTENIDO DE LA NOTICIA
    */
     
     String [] ArrayParagraph;
     JLabel [] Write_News;

     int contador = 0;
     
     muestra.removeAll();
        
        for(int y=0;y<contents.length;y++){
        
        if(ListNews.getSelectedValue().equals(contents[y].getTitle())){
             
            
             showNews.setVisible(true);
             showNews.setSize(1000, 700);
             showNews.setResizable(true);
             
             ArrayParagraph = new String[contents[y].getParagraph().size()];
             Write_News = new JLabel[contents[y].getParagraph().size()];

             
                
                    
                    for (Iterator iterator = contents[y].getParagraph().listIterator(); iterator.hasNext(); ) {
                        
                        String par = (String)iterator.next();

                        ArrayParagraph[contador]=par;
                        contador++;
                        
                    }
                for(int z=0;z<contents[y].getParagraph().size();z++){
                    
                    Write_News[z] = new JLabel(ArrayParagraph[z],SwingConstants.LEFT);
                    muestra.add(Write_News[z]); 
                    muestra.revalidate();
                    muestra.repaint();
                }
             
            showNews.getContentPane().add(muestra, BorderLayout.CENTER);
         
        }
     }
        
        
        
    }//GEN-LAST:event_ButtonShowNewsActionPerformed



    public void showMessageChat(Message msg){
         
        jTextArea1.append(msg.getFrom()+": "+msg.getBody()+ "\n");
     
        
    }
    /*
     * Aqui recibimos el paquete SearchResult para mostrarlo por pantalla
     */
 public void showSearchResult(Message msg){
      
       ButtonShowNews.setVisible(false);
       matrixDos.removeAll();
       matrixDos.setLayout(new GridLayout(3,3));
      
       result = (SearchResultImpl) msg.getProperty("SEARCHRESULT");
       
       contents = new Content[result.Content().size()];
       
       Chk = new JCheckBox[result.Content().size()];
       cont=0;
       
       
      /*
       * Sacamos el contenido del mensaje Searchresult en objetos tipo content
       */
       for (iterador = result.Content().listIterator(); iterador.hasNext(); ) {
           Content c = (Content) iterador.next();
           contents[cont] = c;
           cont++;
        }
       
       for(int i=0;i<contents.length;i++){
           big = contents[i].getImages().getImage();
           Imbig = new ImageIcon(big.getScaledInstance(50, 50, Image.SCALE_DEFAULT));
           Chk[i]=new JCheckBox();
           Chk[i].setIcon(contents[i].getImages());
           Chk[i].setSelectedIcon(Imbig);
           Chk[i].setDisabledIcon(contents[i].getImages());
           matrixDos.add(Chk[i]);
           matrixDos.revalidate();
           matrixDos.repaint();
           
           
       }
    
       
       jScrollPane8.setViewportView(matrixDos);
      
      
    }
 
 public void ShowDownload(String FileName){
      
      model.insertElementAt(FileName, contador_index++);
      jList1.setModel(model);
      
      if(jList1.size() != null){
          
          jButton20.setEnabled(true);
          
      }
      
  }
 /*
  * Mostramos resultado de busquedas de news
  */
 public void ShowResultNew(Message msg){
     
     matrixDos.removeAll();
     result_news = (SearchResultImpl) msg.getProperty("SEARCHRESULT");

     
     model_news = new DefaultListModel();
     contents = new Content[result_news.Content().size()];
     cont_dos =0;
     
      
     for (Iterator iteradorDos = result_news.Content().listIterator(); iteradorDos.hasNext(); ) {
           Content c = (Content) iteradorDos.next();
           contents[cont_dos] = c;
           cont_dos++;
        }
     
     for(int i=0;i<contents.length;i++){

         model_news.insertElementAt(contents[i].getTitle(),i);
         ListNews.setModel(model_news);
         matrixDos.revalidate();
         matrixDos.repaint();
     }
     
     matrixDos.add(ListNews);
    
     
     
     
     jScrollPane8.setViewportView(matrixDos);
     
     ButtonShowNews.setVisible(true);
     

    
     

 }

    
   ///////////PARA EL EDITOR///////////////
   public ImageIcon loadImage(String ruta){
    ImageIcon tmpIconAux = new ImageIcon(ruta);
  int rX=  tmpIconAux.getIconWidth();
  int rY=  tmpIconAux.getIconHeight();
  
  
  if(rX>maxX && rX>rY){
fX=maxX;
fY=(float)(maxX*rY)/rX;


  }else if(rY>maxY && rY>rX){

      fY=maxY;
fX=(float)(maxY*rX)/rY;
}

  else {
fX=rX;
fY=rY;
} 

    ImageIcon tmpIcon = new ImageIcon(tmpIconAux.getImage().getScaledInstance((int)fX, (int) fY, Image.SCALE_DEFAULT));
    return tmpIcon;
    }
    
   
   private static PlanarImage convolveImage (PlanarImage image){

 float[] matrix = { 1/9.0F, 1/9.0F, 1/9.0F, 1/9.0F, 1/9.0F, 1/9.0F, 1/9.0F, 1/9.0F, 1/9.0F };
    KernelJAI kernel = new KernelJAI(3,3,matrix);
    image = JAI.create("convolve", image, kernel);
    return image;
}

private static PlanarImage scaleImage (PlanarImage image, float scaleX, float scaleY){

                      ParameterBlock params = new ParameterBlock();
                        params.addSource(image);
                        params.add(scaleX);
                        params.add(scaleY);
                        params.add(0.0F);
                        params.add(0.0F);
                        params.add(new InterpolationNearest());

                        image= JAI.create("scale",params, null);

                        return image;
          }

public static PlanarImage brightnessImage(PlanarImage image, int contrast)
{
ParameterBlock param = new ParameterBlock();
        param.addSource(image);
        byte lookUpTableData[];
        lookUpTableData = new byte[256];
        for(int i = 0; i < 256; i++){
                lookUpTableData[i] = clampByte(i + contrast);
        }

        LookupTableJAI lookUp = new LookupTableJAI(lookUpTableData);
        param.add(lookUp);

        image = JAI.create("lookup", param, null);

        return image;
}

public static PlanarImage contrastImage(PlanarImage image, float contrast)
{
ParameterBlock param = new ParameterBlock();
param.addSource(image); 
param.add(null); 
param.add(1); 
param.add(1); 

PlanarImage meanImage = JAI.create("mean", param, null);
double[] mean = (double[])meanImage.getProperty("mean");
double sum = 0;
for (int i=0; i < mean.length; i++)
{
sum += mean[i];
}

int average = (int) sum / mean.length;

byte[]lut = new byte[256] ;
for (int i = 0; i < 256; i++ )
{
lut[i] = (byte)(average + (int)((i - average) * contrast));
}
LookupTableJAI lookup = new LookupTableJAI(lut);

ParameterBlock param2 = new ParameterBlock();
param2.addSource(image);
param2.add(lookup);

image = JAI.create("lookup", param2, null);

return image;
}


private static byte clampByte(int i) {
        if(i > 255)
                return -1;
        if(i < 0)
                return 0;
        else
                return (byte)i;
    }


private static PlanarImage GrayscaleImage(PlanarImage image) {

        double[][] grayToGray = {{1}};
        double[][] rgbToGray = {{0.299, 0.587, 0.114, 0}};
        double[][] alphaToGray = {{0.299, 0.587, 0.114, 0, 0}};

        ParameterBlock param = new ParameterBlock();
        param.addSource(image);

        switch (image.getNumBands()) {
            case 1:
                param.add(grayToGray);
                break;
            case 4:
                param.add(alphaToGray);
                break;
            default:
                param.add(rgbToGray);
        }

        return JAI.create("BandCombine", param);
    }


public static PlanarImage invertImage(PlanarImage original) {
        ParameterBlock param = new ParameterBlock();
        param.addSource(original);

        return JAI.create("Invert", param);
    }


public static void guardarImage(PlanarImage image, FileOutputStream out, String archivo,String format){

                    try {
                       
                        JAI.create("filestore", image,archivo,format);
                        out.close();
                    } catch (IOException e) {
                        System.out.println("IOException at encoding..");
                        System.exit(1);
                    }
            }


    

  int cont_rbutton;
  Thumbnail ImageTh = new ThumbnailImp();
  searchProfile search = null;
  JCheckBox CheckBox =null;
  SearchResultImpl result = null;
  SearchResultImpl result_news=null;
  int cont;
  JPanel matrixDos = new JPanel();
  String QueryType="";
  Image big = null;
  ImageIcon Imbig = null;
  Iterator iterador=null;
  Content [] contents =null;
  JCheckBox [] Chk =null;
  
  ArrayList<UserContent> ArrayUc = null;
  UserContent Uc =null;
  
  DefaultListModel model = new DefaultListModel();
  int contador_index=0;
  
  DefaultListModel model_news;
  JList ListNews = new JList();
  int cont_dos;
  
  JFrame showNews = new JFrame();
  JPanel muestra = new JPanel();
  
  
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton Add;
    private javax.swing.JButton ButtonShowNews;
    private java.awt.List ChatList;
    private javax.swing.JButton Delete;
    private javax.swing.JButton DownloadButton;
    private javax.swing.JLayeredPane EditorLayeredPane;
    private javax.swing.JLayeredPane MyPhotosLayeredPane;
    private javax.swing.JLayeredPane ProfileLayeredPane;
    private javax.swing.JLayeredPane SearchLayeredPane;
    private javax.swing.JButton Send;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton10;
    private javax.swing.JButton jButton11;
    private javax.swing.JButton jButton12;
    private javax.swing.JButton jButton13;
    private javax.swing.JButton jButton14;
    private javax.swing.JButton jButton15;
    private javax.swing.JButton jButton16;
    private javax.swing.JButton jButton17;
    private javax.swing.JButton jButton18;
    private javax.swing.JButton jButton19;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton20;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton7;
    private javax.swing.JButton jButton8;
    private javax.swing.JButton jButton9;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JEditorPane jEditorPane1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JList jList1;
    private javax.swing.JRadioButton jRadioButton3;
    private javax.swing.JRadioButton jRadioButton4;
    private javax.swing.JRadioButton jRadioButton5;
    private javax.swing.JRadioButton jRadioButton6;
    private javax.swing.JRadioButton jRadioButton7;
    private javax.swing.JRadioButton jRadioButtonKeyword;
    private javax.swing.JRadioButton jRadioButtonLocalization;
    private javax.swing.JRadioButton jRadioButtonOntology;
    private javax.swing.JRadioButton jRadioButtonTitle;
    private javax.swing.JRadioButton jRadioButtonUser;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane10;
    private javax.swing.JScrollPane jScrollPane11;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JScrollPane jScrollPane6;
    private javax.swing.JScrollPane jScrollPane8;
    private javax.swing.JScrollPane jScrollPane9;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JSlider jSlider1;
    private javax.swing.JSlider jSlider2;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTabbedPane jTabbedPane2;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JTextArea jTextArea2;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    private javax.swing.JTextField jTextField4;
    private javax.swing.JTextField jTextField5;
    private javax.swing.JTextField jTextField6;
    private javax.swing.JTextPane jTextPane1;
    private javax.swing.JTextPane jTextPane2;
    private javax.swing.JTextPane jTextPane3;
    private java.awt.Panel panel11;
    // End of variables declaration//GEN-END:variables
} 
